package chai.ning.date;

import java.util.Arrays;
import java.util.Date;

public class DateTest4_compare {

	public static void main(String[] args) {

		final long time = 1000L * 60 * 60;
		final long day = 1000L * 60 * 60 * 24;
		final long mon = 1000L * 60 * 60 * 24 * 30;
		final long cur = System.currentTimeMillis();

		Date[] dates = new Date[8];

		dates[0] = new Date(cur + mon + time);
		dates[1] = new Date(cur - mon - time);
		dates[2] = new Date(cur + day);
		dates[3] = new Date(cur - day);
		dates[4] = new Date(cur + mon + day);
		dates[5] = new Date(cur + mon - day);
		dates[6] = new Date(cur - mon - day);
		dates[7] = new Date(cur - mon + day);

		for (int i = 0, n = dates.length; i < n - 1; i++) {
			for (int j = 0; j < n - 1 - i; j++) {
				if (dates[j].before(dates[j + 1])) {
					Date temp = dates[j];
					dates[j] = dates[j + 1];
					dates[j + 1] = temp;
				}
			}
		}
		for (int i = 0; i < dates.length; i++) {
			System.out.println(dates[i].toString());
		}
		System.out.println(" -------------- ");
		Arrays.sort(dates);
		System.out.println(Arrays.toString(dates));
	}

}
